package com.pic.mgt.haishin.converter;

import java.io.IOException;

import com.pic.mgt.haishin.unit.HaishinMessage;
import com.pic.mgt.monitor.MessageUnitConverter;
import com.pic.mgt.monitor.WrongUnitFormatException;
import com.pic.mgt.monitor.parser.FormatParser;
import com.pic.mgt.unit.Unit;

public class HaishinMessageUnitConverter extends MessageUnitConverter {
	private HaishinMessage haishinMessage;
	
	private FormatParser messageTerminalIdParser;
	
	@Override
	protected void parseIGXTypeContent(Unit unit)
									throws IOException,
									       WrongUnitFormatException {
		this.haishinMessage = (HaishinMessage)unit;
		
		// 分析並填入集配信型態的內容(第三層級)
		doFill();
	}
	
	/*
	 * 放入訊息型態內容資訊:
	 * (1) Terminal ID
	 */
	private void doFill() throws WrongUnitFormatException {
		// --------------------- (1) Terminal Id ---------------------
		// throws WrongUnitFormatException
		fillTerminalId();
	}
	
	private void fillTerminalId() throws WrongUnitFormatException  {
		this.haishinMessage.setTerminalId((String)
				this.messageTerminalIdParser.parse(super.confirmationFile.getName()));
	}
	
	// --- getter and setter ---
	
	public void setMessageTerminalIdParser(FormatParser messageTerminalIdParser) {
		this.messageTerminalIdParser = messageTerminalIdParser;
	}
}
